package PTA_JAVA.JavaB.Javademo18;
import java.lang.reflect.*;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] types = {"Student","Teacher"};
        //输入种子seed，并用其初始化Random对象
        int seed = Integer.parseInt(sc.next());
        Random random = new Random(seed);
        //输入对象生成数量n
        int n = Integer.parseInt(sc.next());
        Person[] person = new Person[n];
        //以下是生成n个对象的循环
        for (int i = 0; i < n; i++) {
            //使用random.nextInt(2)从types数组中随机选取元素x并输出
            String x=types[random.nextInt(2)];
            //根据x选择输入相应的参数
            if(x.equals("Student")){
                System.out.println("Student");
                Student stu = new Student(i,sc.next(),sc.next(),Integer.parseInt(sc.next()),sc.next());
                person[i]=stu;
            }else if(x.equals("Teacher")){
                System.out.println("Teacher");
                Teacher tea = new Teacher(i,sc.next(),sc.next(),sc.next(),Double.parseDouble(sc.next()));
                person[i]=tea;
            }
        }

        //输出集合中的每个对象的toString
        for(Person i:person){
            System.out.println(i.toString());
        }
        //对集合进行排序并输出提示信息
        System.out.println("afterSort:");
        Arrays.sort(person);
        //输出排序后集合的toString
        for(Person i:person){
            System.out.println(i.toString());
        }
        //请在此粘贴上检验程序代码
        Class interfaces[] = Person.class.getInterfaces();
        for(Class inf:interfaces) {
            System.out.println(inf);
        }
    }

}
class Person implements Comparable{
    private int id;
    private String name;
    private String birthDate;

    public Person(int id, String name, String birthDate) {
        this.id = id;
        this.name = name;
        this.birthDate = birthDate;
    }

    public int getId() {
        return id;
    }

    public String getBirthDate() {
        return birthDate;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person [" +
                "id=" + id +
                ", name=" + name +
                ", birthDate=" + birthDate +
                ']';
    }

    @Override
    public int compareTo(Object o) {
        if(o instanceof Person){
            Person p=(Person) o;
            if(this.name.compareTo(p.name)>0){
                return -1;
            }else if(this.name.compareTo(p.name)<0){
                return 1;
            }else if(this.id-p.id>0){
                return -1;
            }else if(this.id-p.id<0){
                return 1;
            }
        }
        return 0;
    }
}
class Student extends Person{
    private int enrollmentYear;
    private String clazzName;

    public Student(int id, String name, String birthDate,int enrollmentYear,String clazzName) {
        super(id, name, birthDate);
        this.enrollmentYear = enrollmentYear;
        this.clazzName = clazzName;
    }

    @Override
    public String toString() {
        return super.toString()+"\n"+"Student [" +
                "enrollmentYear=" + enrollmentYear +
                ", clazzName=" + clazzName +
                "]";
    }
}
class Teacher extends Person{
    private String department;
    private double salary;


    public Teacher(int id, String name, String birthDate,String department,double salary) {
        super(id, name, birthDate);
        this.department = department;
        this.salary = salary;
    }

    @Override
    public String toString() {
        return super.toString()+"\n"+"Teacher [" +
                "department=" + department +
                ", salary=" + salary +
                "]";
    }
}
